import permission from "@/js_sdk/wa-permission/permission.js";
//手机权限，摄像头
export function permissionCheck() {
	return new Promise(async (resolve, reject) => {
		if (uni.getSystemInfoSync().platform === 'ios') {
			const camera = permission.judgeIosPermission("camera"); //判断ios是否给予摄像头权限
			if (camera) {
				resolve();
			} else {
				reject('需要开启相机使用权限');
			}
		} else {
			let camera = await permission.requestAndroidPermission(
				"android.permission.CAMERA"); //判断安卓是否给予摄像头权限
			if (camera == -1) {
				reject('需要开启相机使用权限');
			} else {
				resolve();
			}
		}
	})
}
// 手机权限,相册存储
export function permissionPhotoLibrary() {
	return new Promise(async (resolve, reject) => {
		if (uni.getSystemInfoSync().platform === 'ios') {
			const photoLibrary = permission.judgeIosPermission("photoLibrary"); //判断ios是否给予相册权限
			if (photoLibrary) {
				resolve();
			} else {
				reject('需要开启相册存储权限');
			}
		} else {
			let photoLibrary = await permission.requestAndroidPermission(
				"android.permission.WRITE_EXTERNAL_STORAGE"); //判断安卓是否给予相册权限
			if (photoLibrary == -1) {
				reject('需要开启相册存储权限');
			} else {
				resolve();
			}
		}
	})
}

//跳转到手机开启权限的界面
export function phonePermissionSetting() {
	permission.gotoAppPermissionSetting();
}